#include<bits/stdc++.h>
using namespace std;
const int N=701;

short h[N][N];
int tag[N][N];
int n,m;
const int dr[9] = {-1,-1,-1,0,0,0,1,1,1};
const int dc[9] = {-1,0,1,-1,0,1,-1,0,1};

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            scanf("%sd",&h[i][j]);
        }
    }
    int r1,c1;
    int r2,c2;
    bool is_hill;
    memset(tag,0,sizeof(tag));
    int cnt = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            short h0 = h[i][j];
            is_hill = true;
            for(int u=0;u<9;u++){
                r1 = i+dr[u];
                c1 = j+dc[u];
                if(r1<=0||r1>n||c1<=0||c1>m) continue;
                if(h[r1][c1]>h0){
                    is_hill = false;
                    break;
                }
            }
            if(is_hill){
                cout<<"hill:"<<i<<' '<<j<<endl;
                cnt++;
                for(int u=0;u<9;u++){
                    r1 = i+dr[u];
                    c1 = j+dc[u];
                    if(r1<=0||r1>n||c1<=0||c1>m) continue;
                    if(tag[r1][c1]){
                        int t = tag[r1][c1];
                        cnt--;
                        for(int v=0;v<9;v++){
                            r2 = i+dr[v];
                            c2 = j+dc[v];
                            if(r2<=0||r2>n||c2<=0||c2>m) continue;
                            tag[r2][c2] = t;
                        }
                        break;
                    }else{
                        tag[r1][c1] = cnt;
                    }
                }
            }
        }
    }
    printf("-----\n");
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++){
            printf("%d ",tag[i][j]);
        }
        printf("\n");
    }
    printf("%d\n",cnt);
    return 0;
}